package com.fesine.ch02.throwExceptionNoLock;

/**
 * 当一个线程执行的代码出现异常时，其所持有的锁会自动释放
 * @Author: Fesine
 * @CreateDate:2016/6/29
 * @UpdateUser:修改人名称
 * @UpdateDate:2016/6/29
 * @UpdateRemark:修改具体的内容
 */
public class Service {
    synchronized public void testMehod() {
        if (Thread.currentThread().getName().equals("a")) {
            System.out.println("ThreadName=" + Thread.currentThread().getName()
                    + " run beginTime=" + System.currentTimeMillis());
            int i = 1;
            while (i == 1) {
                if (("" + Math.random()).substring(0, 8).equals("0.123456")) {
                    System.out.println("ThreadName=" + Thread.currentThread().getName()
                            + " run exceptionTime=" + System.currentTimeMillis());
                    Integer.parseInt("a");
                }
            }
        } else {
            System.out.println("ThreadName=" + Thread.currentThread().getName()
                    + " run Time=" + System.currentTimeMillis());
        }
    }
}
